package com.Tadama.Forms;

import com.Tadama.MIDlet.TadamaMIDlet;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import com.Tadama.MIDlet.TadamaMIDlet;
import com.Tadama.Utility.CommandBuilder;
import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Display;

public class lstMenu extends List implements CommandListener{
    private TadamaMIDlet mainMIDlet;
    private Command cmExit = CommandBuilder.getExit();
    private Command cmSelect = CommandBuilder.getSelect();
    private static final String[]MENU_ITEMS={"Sincronizar",
                                             "Nuevo Cliente",
                                             "Pedido",
                                             "Devolucion",
                                             "Cierre de Dia"};
    private static final  Image[] IMAGE_ITEMS ={loadImage("/com/Tadama/img/item1.png"),
                                                loadImage("/com/Tadama/img/item2.png"),
                                                loadImage("/com/Tadama/img/item3.png"),
                                                loadImage("/com/Tadama/img/item3.png"),
                                                loadImage("/com/Tadama/img/item4.png")};
    
    public lstMenu(TadamaMIDlet mainMIDlet, String title, int listType) {
        super(title, listType);
        
        this.addCommand(cmExit);
        this.addCommand(cmSelect);
        this.setCommandListener(this);
        this.mainMIDlet = mainMIDlet;
        for(int i =0;i<=4;i++){
            this.append(MENU_ITEMS[i], IMAGE_ITEMS[i]);
        }
    }
    
    private static Image loadImage(String name) {
        Image image = null;
        try {
            image = Image.createImage(name);
        }catch (IOException ioe){
            System.out.println(ioe);
        }
        return image;
    }
    
    public void commandAction(Command c, Displayable d) {
        int menuIndex = this.getSelectedIndex();
        if(c==lstMenu.SELECT_COMMAND || c== cmSelect){
            switch(menuIndex){
                case 0:{ //Sincronizacion
                    Display.getDisplay(mainMIDlet).setCurrent(new frmSincronizar(mainMIDlet, this));
                    break;
                }
                case 1:{ //Regristro Nuevo Cliente
                    Display.getDisplay(mainMIDlet).setCurrent(new frmNuevoCliente(mainMIDlet,this));
                    break;
                }
                case 2:{ //Toma de Pedido
                    Display.getDisplay(mainMIDlet).setCurrent(new frmBuscarClientes("Eleguir Cliente",mainMIDlet,this));
                    break;
                }
                case 3:{ //Devolucion
                    Display.getDisplay(mainMIDlet).setCurrent(new frmBuscarPedidos("Eleguir",mainMIDlet,this));
                    break;
                }
                case 4:{ //Cierre dia
                    Display.getDisplay(mainMIDlet).setCurrent(new frmBuscarPedidos("Eleguir",mainMIDlet,this));
                    break;
                }
            }
        }/*
        if (c == cmExit) {mainMIDlet.destroyApp(true);}
        else if (c == cmSelect){
            switch(menuIndex){
                case 0:{ //Regristro Nuevo Cliente
                    System.out.println("Nuevo Cliente");
                    //setDisplay(frmNuevoCliente);
                    Display.getDisplay(mainMIDlet).setCurrent(new frmNuevoCliente(mainMIDlet,this));
                    break;
                }
                case 1:{ //Realiza toma de pedido
                    System.out.println("Realiza Pedido");
                    Display.getDisplay(mainMIDlet).setCurrent(new frmNuevoCliente(mainMIDlet,this));
                    break;
                }
                case 2:{ //Devolucion
                    System.out.println("Devolucion");
                    Display.getDisplay(mainMIDlet).setCurrent(new frmNuevoCliente(mainMIDlet,this));
                    //setDisplay(frmCargarPost);
                    break;
                }
                case 3:{ //Realiza Entrega de Pedido
                    Display.getDisplay(mainMIDlet).setCurrent(new frmNuevoCliente(mainMIDlet,this));
                    System.out.println("Realiza Entrega");                   
                    break;
                }
            }
        }*/
    }
}